<?php
class ome_branch_product_pos_to_import {

    function run(&$cursor_id,$params){

        $bpObj = &app::get($params['app'])->model($params['mdl']);
        $branchObj = &app::get('ome')->model('branch');
        $branch_pos_obj = &app::get('ome')->model('branch_pos');
        $pobj = &app::get('ome')->model('products');
        $Sdf = array();
        $bp = array();
        $Sdf = $params['sdfdata'];

        foreach ($Sdf as $v){
            $bp = array();
            //获取仓库ID
            $branch = $branchObj->dump(array('name'=>trim($v[3])), 'branch_id');
            $branch_pos = $branch_pos_obj->dump(array('store_position'=>trim($v[0]), 'branch_id'=>$branch['branch_id']), 'pos_id');
            $products = $pobj->dump(array('barcode'=>trim($v[2])), 'product_id');
            if ($branch['branch_id']){
                /*if(isset($v['pp_id']) && !empty($v['pp_id'])){
                    $bp['pp_id'] = $v['pp_id'];
                }*/
                $bp['product_id'] = $products['product_id'];
                $bp['branch_id'] = $branch['branch_id'];
                $bp['create_time'] = time();
                $bp['pos_id'] = $branch_pos['pos_id'];
                $bpObj->save($bp);
            }
        }
        return false;
    }
}
